<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
//Includes
use_unit("components4phpfull/jtsitetheme.inc.php");
use_unit("components4phpfull/jtdatepicker.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class Route_Edit extends Page
{
       public $imgBack = null;
       public $chkovernight = null;
       public $edTotal = null;
       public $edStartHrs = null;
       public $Label4 = null;
       public $edStopMin = null;
       public $edStopHrs = null;
       public $edStartMin = null;
       public $Label3 = null;
       public $edHrs = null;
       public $lblHrs = null;
       public $lblStopTime = null;
       public $lblStartTime = null;
       public $JTSiteTheme1 = null;
       public $hiddenRoute = null;
       public $hiddenEmp = null;
       public $btnCancel = null;
       public $btnSubmit = null;
       public $memoDesc = null;
       public $Label11 = null;
       public $edmiles = null;
       public $Label10 = null;
       public $edOdstop = null;
       public $edOdStart = null;
       public $Label9 = null;
       public $Label8 = null;
       public $edShift = null;
       public $Label7 = null;
       public $cmbveh = null;
       public $Label6 = null;
       public $Label2 = null;
       public $Label1 = null;
       public $JTEnd = null;
       public $JTstart = null;
       public $Image1 = null;
       function imgBackJSMouseOut($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgBack'].src="image/btn_back.png"
       <?php

       }

       function imgBackJSMouseOver($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgBack'].src="image/btn_back2.png"
       <?php

       }

       function edOdstopJSKeyUp($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.Route_Edit.edhours.value = (document.Route_Edit.edTimeStop.value) - (document.Route_Edit.edtimeStart.value);
       <?php

       }

       function edOdStartJSKeyUp($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.Route_Edit.edhours.value = (document.Route_Edit.edTimeStop.value) - (document.Route_Edit.edtimeStart.value);
       <?php

       }

       function edStopMinJSBlur($sender, $params)
       {
       echo $this->edStopMin->ajaxCall("computeHrs");
       }

       function edStopHrsJSBlur($sender, $params)
       {
       echo $this->edStopMin->ajaxCall("computeHrs");
       }


       function computeHrs($sender, $params)
       {
       $startHrs = $this->edStartHrs->Text;
       $startMin = $this->edStartMin->Text;
       $endHrs = $this->edStopHrs->Text;
       $endMin = $this->edStopMin->Text;

       $start = strtotime($startHrs." hours ".$startMin." minutes");
       $end = strtotime($endHrs." hours ".$endMin." minutes");
       $answer = $end - $start;

       $this->edTotal->Text = date('H\h i\m',$answer);
       $ansMin = date('i',$answer);
       $ansHrs = date('H',$answer);
       $compAns =($ansMin/60) + $ansHrs;
       $this->edHrs->Text = round($compAns,2);
       }



       function btnCancelClick($sender, $params)
       {
       redirect('route_list.php?emp='.$this->hiddenEmp->getValue().'&route='.$this->hiddenRoute->getValue());


       }

       function btnSubmitClick($sender, $params)
       {
       if($this->chkovernight->Checked==true)
       {
       $overnight = '1';
       }
       else
       {
       $overnight = '0';
       }

       mysql_query("update route_tbl set
       vehicle = '".$this->cmbveh->getItemIndex()."',
       start_date = '".$this->JTstart->Date."',
       end_date = '".$this->JTEnd->Date."',
       start_hrs = '".$this->edStartHrs->Text."',
       start_min = '".$this->edStartMin->Text."',
       stop_hrs = '".$this->edStopHrs->Text."',
       stop_min = '".$this->edStopMin->Text."',
       total_hrs = '".$this->edHrs->Text."',
       hrs = '".$this->edTotal->Text."',
       shift = '".$this->edShift->Text."',
       odometer_start = '".$this->edOdStart->Text."',
       odometer_stop = '".$this->edOdstop->Text."',
       miles = '".$this->edmiles->Text."',
       description = '".$this->memoDesc->Text."',
       overnight = '".$overnight."'
       where emp_id ='".$this->hiddenEmp->getValue()."' and route_id = '".$this->hiddenRoute->getValue()."'")or die ("UPDATE ROUTE EDIT-".mysql_error());

       redirect('route_list.php?emp='.$this->hiddenEmp->getValue().'&route='.$this->hiddenRoute->getValue());


       }

       function Route_EditCreate($sender, $params)
       {
       $emp = $_GET['emp'];
       $route = $_GET['route'];
       $this->hiddenEmp->setValue($emp);
       $this->hiddenRoute->setValue($route);

       $this->imgBack->setLink('route_list.php?emp='.$this->hiddenEmp->getValue().'&route='.$this->hiddenRoute->getValue());


       $query_route = "select * from route_tbl where emp_id='".$this->hiddenEmp->getValue()."' and route_id='".$this->hiddenRoute->getValue()."'";
       $result_route_show = mysql_query($query_route)or die("SELECT ROUTE - " . mysql_error());
       $row_route = mysql_fetch_array($result_route_show);

       $this->JTstart->Date=$row_route['start_date'];
       $this->JTEnd->Date=$row_route['end_date'];
       $this->edStartHrs->Text=$row_route['start_hrs'];
       $this->edStartMin->Text=$row_route['start_min'];
       $this->edStopHrs->Text=$row_route['stop_hrs'];
       $this->edStopMin->Text=$row_route['total_hrs'];
       $this->edHrs->Text=$row_route['hrs'];
       $this->edShift->Text=$row_route['shift'];
       $this->edOdStart->Text=$row_route['odometer_start'];
       $this->edOdstop->Text=$row_route['odometer_stop'];
       $this->edmiles->Text=$row_route['miles'];
       $this->memoDesc->Text=$row_route['description'];

       if($row_route['overnight']==1)
       {
       $this->chkovernight->Checked=true;
       }
       else
       {
       $this->chkovernight->Checked=false;
       }


       $this->cmbveh->Clear();
       $this->cmbveh->ItemIndex=$row_route['vehicle'];
        $result_veh = mysql_query("select * from vehicle_tbl where company_id='1'");

        while($row_veh = mysql_fetch_array($result_veh))
        {
            $this->cmbveh->AddItem('Plate No:'.$row_veh['veh_num'].'  '.$row_veh['year'].''.$row_veh['manufacturer_name'].''.$row_veh['model_name'], null, 'Plate No:'.$row_veh['veh_num'].'  '.$row_veh['year'].''.$row_veh['manufacturer_name'].''.$row_veh['model_name']);
        }


       }


}

global $application;

global $Route_Edit;

//Creates the form
$Route_Edit=new Route_Edit($application);

//Read from resource file
$Route_Edit->loadResource(__FILE__);

//Shows the form
$Route_Edit->show();

?>